//
//  BillSelectViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/3/8.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "BillSelectViewController.h"
#import "BillSelectView.h"
#import "BillSelectTableViewCell.h"
#import "BillSelectSectionHeaderView.h"
//弹出分类框
#import "PopCategoryView.h"
//弹出筛选框
#import "PopFiltrateView.h"
#import "SwipeCategoryCollectionViewCell.h"
#import "AppTools.h"
#import "PopCategoryCollectionReusableView.h"
#import "BRDatePickerView.h"
//账单详情
#import "BillDetailViewController.h"
#import "BillSelectModelPack.h"
#import "BillSelectDetaileModelPack.h"
//无账单显示
#import "BillSelectNoneView.h"

#import <MJRefresh.h>

@interface BillSelectViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UITextFieldDelegate>
@property(nonatomic,strong)BillSelectView *bv;
@property(nonatomic,strong)BillSelectNoneView *billSelectNoneView;
@property(nonatomic,strong)BillSelectSectionHeaderView *sectionHeaderView;
@property(nonatomic,strong)UITableView *tableView;



@property(nonatomic,strong)NSMutableArray *swipeArray;
@property(nonatomic,strong)NSMutableArray *categoryArray;


@property(nonatomic,strong)NSIndexPath* lastIndexPath;

//分类框
@property(nonatomic,strong)PopCategoryView *pv;
//筛选框
@property(nonatomic,strong)PopFiltrateView *popfiltraView;

@property(nonatomic,strong)UIView *bottomView;

/**
 点击刷卡收款变成2个分区，其余一个分区
 */
@property(nonatomic,assign)NSInteger collectionViewSectionNum;

//tableView分区数
@property(nonatomic,strong)NSMutableArray *tableViewSectionArray;

//条件查询账单
@property(nonatomic,strong)NSString *minAmount;
@property(nonatomic,strong)NSString *maxAmount;
@property(nonatomic,strong)NSString *startTime;
@property(nonatomic,strong)NSString *endTime;
@property(nonatomic,strong)NSString *month;
@property(nonatomic,strong)NSString *orderType;

// 上拉下拉刷新相关属性
@property(nonatomic,assign) NSInteger curPageNum;
@property(nonatomic,strong) NSString *ifHasMore; // 是否有更多数据 0:无 1:有
@property(nonatomic,assign) ETRefreshType refreshType;
@property(nonatomic,assign) BOOL isLoading;


@end

@implementation BillSelectViewController


#pragma mark 上拉刷新&下拉刷新
- (void)createHeaderView{
    MJRefreshNormalHeader *headerView = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    // 设置文字
    [headerView setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [headerView setTitle:@"释放刷新" forState:MJRefreshStatePulling];
    [headerView setTitle:@"加载中 ..." forState:MJRefreshStateRefreshing];
    // 设置字体
    headerView.stateLabel.font = [UIFont systemFontOfSize:15];
    headerView.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
    // 设置颜色
    headerView.stateLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    headerView.lastUpdatedTimeLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    self.tableView.mj_header = headerView;
    //隐藏上次刷新时间
    headerView.lastUpdatedTimeLabel.hidden = YES;
}

- (void)createFooterView
{
    MJRefreshBackNormalFooter *footerView = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    // 设置文字
    [footerView setTitle:@"上拉刷新" forState:MJRefreshStateIdle];
    [footerView setTitle:@"正在加载更多数据" forState:MJRefreshStateRefreshing];
    [footerView setTitle:@"-已经到底了-" forState:MJRefreshStateNoMoreData];
    // 设置字体
    footerView.stateLabel.font = [UIFont systemFontOfSize:13];
    // 设置颜色
    footerView.stateLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    self.tableView.mj_footer = footerView;
}

- (void)loadNewData{
    if (self.isLoading) {
        return;
    }
    self.curPageNum = 1;
    self.refreshType = ETRefreshDown;
    
    [self getBill];
    
}

- (void)loadMoreData{
    if (self.isLoading) {
        return;
    }
    self.refreshType = ETRefreshUp;
    self.curPageNum++;
    if ([self.ifHasMore isEqualToString:@"0"]) {
        /*
         [self showSuccessResultTips:@"无更多数据" animated:YES forSeconds:SUCCESS_SHOW_TIME_DEF];
         */
        [self.tableView.mj_footer endRefreshingWithNoMoreData];
        return;
    }
    
    [self getBill];
}



-(NSMutableArray *)tableViewSectionArray
{
    if (_tableViewSectionArray == nil) {
        _tableViewSectionArray = [NSMutableArray array];
    }
    return _tableViewSectionArray;
}

-(NSMutableArray *)categoryArray
{
    if (_categoryArray == nil) {
        _categoryArray = [NSMutableArray array];
    }
    return _categoryArray;
}
-(NSMutableArray *)swipeArray
{
    if (_swipeArray == nil) {
        _swipeArray = [NSMutableArray array];
    }
    return _swipeArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:244 / 255.0 blue:246 / 255.0 alpha:1];
    self.title = @"账单查询";
    
    
    //创建筛选View
    [self createTopView];
    //创建tableView
    [self createTableView];
    // 上拉下拉刷新相关设置
    self.curPageNum = 1;
    self.ifHasMore = @"1";
    [self createFooterView];
    [self createHeaderView];
    
    
    //点击分类
    [self.bv.clearBtn addTarget:self action:@selector(categoryBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    //点击筛选
    [self.bv.filtrateClearBtn addTarget:self action:@selector(filtrateClearBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    //创建筛选View
    self.popfiltraView = [[PopFiltrateView alloc] init];
    self.popfiltraView.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 110);
    self.popfiltraView.minimumAmountTf.inputAccessoryView = [self addToolbar];
    self.popfiltraView.maxAmountTf.inputAccessoryView = [self addToolbar];
    [self.view addSubview:self.popfiltraView];
    //退键盘
    self.popfiltraView.minimumAmountTf.delegate = self;
    self.popfiltraView.maxAmountTf.delegate = self;
    //月份和时间显示当前的
    self.popfiltraView.monthLab.text = [self getCurrentMonthDate];
    self.popfiltraView.daybeginValueLab.text = [self getCurrentDayDate];
    self.popfiltraView.dayEndValueLab.text = [self getCurrentDayDate];
    //重置确定按钮事件
    [self.popfiltraView.resetBtn addTarget:self action:@selector(popfiltraresetAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.popfiltraView.confirmBtn addTarget:self action:@selector(popfiltraconfirmAction) forControlEvents:(UIControlEventTouchUpInside)];
    //把分类View拿到最上层  防止弹框遮盖
    [self.view bringSubviewToFront:self.popfiltraView];
    
    //创建分类View
    self.pv = [[PopCategoryView alloc] init];
    self.pv.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 110);
    [self.view addSubview:self.pv];
    //把分类View拿到最上层  防止弹框遮盖
    [self.view bringSubviewToFront:self.bv];
    
    
    
    //创建bottomView
    self.bottomView = [[UIView alloc] init];
    self.bottomView.backgroundColor = [UIColor clearColor];
    self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 0);
    [self.view addSubview:self.bottomView];
    //增加手势 点击收回弹框
    self.bottomView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [self.bottomView addGestureRecognizer:tap];
    
    //创建collectionView
    [self createCollectionView];
    //确定按钮事件
    [self.pv.confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    //重置按钮点击事件
    [self.pv.resetBtn addTarget:self action:@selector(resetBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    //按月查询
    [self.popfiltraView.monthBtn addTarget:self action:@selector(monthBtnAction)
                          forControlEvents:(UIControlEventTouchUpInside)];
    //按日查询
    [self.popfiltraView.dayBtn addTarget:self action:@selector(dayBtnAction)
                          forControlEvents:(UIControlEventTouchUpInside)];
    //默认按月选择
    self.popfiltraView.monthBtn.selected = YES;
    //开始时间事件
    UITapGestureRecognizer *startTimeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(startTimeTapAction)];
    self.popfiltraView.daybeginValueLab.userInteractionEnabled = YES;
    [self.popfiltraView.daybeginValueLab addGestureRecognizer:startTimeTap];
    
    UITapGestureRecognizer *endTimeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(endTimeTapAction)];
    self.popfiltraView.dayEndValueLab.userInteractionEnabled = YES;
    [self.popfiltraView.dayEndValueLab addGestureRecognizer:endTimeTap];
    //初始状态选择  默认按月选择
    self.popfiltraView.selectDayView.hidden = YES;
    self.popfiltraView.selectMonthView.hidden = NO;
    
    //后端请求数据列表
    [self getBill];
}

//数字键盘加完成按钮
- (UIToolbar *)addToolbar
{
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 40)];
    toolbar.backgroundColor = ETColorWithRGB(232, 232, 232);
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn.backgroundColor = [UIColor whiteColor];
    [btn setTitle:@"完成" forState:(UIControlStateNormal)];
    [btn setTitleColor:ETColorWithRGB(0, 0, 0) forState:(UIControlStateNormal)];
    btn.layer.borderColor = ETColorWithRGB(0, 0, 0).CGColor;
    btn.layer.borderWidth = 1;
    btn.layer.cornerRadius = 4;
    btn.frame = CGRectMake(0, 0, 76, 28);
    [btn addTarget:self action:@selector(textFieldDone) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithCustomView:btn];
    toolbar.items = @[space, bar];
    return toolbar;
}
-(void)textFieldDone
{
    [self.view endEditing:YES];
}



//获取当前月份
-(NSString *)getCurrentMonthDate
{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM";
    NSString *dateString = [formatter stringFromDate:date];
    return dateString;
}
//获取当前日期
-(NSString *)getCurrentDayDate
{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
    NSString *dateString = [formatter stringFromDate:date];
    return dateString;
}


-(void)getBill
{
    BillSelectRequest *request = [[BillSelectRequest alloc] init];
    request.pageSize = PAGESIZE;
    request.pageNum = [NSString stringWithFormat:@"%ld",(long)self.curPageNum];
    request.month = self.month;
    request.startTime = self.startTime;
    request.endTime = self.endTime;
    request.minAmount = self.minAmount;
    request.maxAmount = self.maxAmount;
    request.orderType = self.orderType;
    self.isLoading = YES;
    NSDictionary *dic = [request mj_keyValues];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/order/tradeListC0100"];
    __weak __typeof(self) weakSelf = self;
    [[ETONEHttpClient sharedInstance] doHTTPSPOSTNOTips:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        self.isLoading = NO;
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            
            [weakSelf dealMessageResponse:responseObject];
        }else
        {
            //无数据 加载无数据View
//            [self.tableView removeFromSuperview];
            [self.tableViewSectionArray removeAllObjects];
            [self.tableView reloadData];
            self.billSelectNoneView = [[BillSelectNoneView alloc] initWithFrame:(CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50))];
            [self.view addSubview:self.billSelectNoneView];
            //把无消息View放到下一层  防止弹框遮盖
//            [self.view sendSubviewToBack:self.billSelectNoneView];
        }
        
        
        
    } FailedHandler:^(NSError *error) {
        
        self.isLoading = NO;
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
        //无数据 加载无数据View
//        [self.tableView removeFromSuperview];
        [self.tableViewSectionArray removeAllObjects];
        [self.tableView reloadData];
        self.billSelectNoneView = [[BillSelectNoneView alloc] initWithFrame:(CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50))];
        [self.view addSubview:self.billSelectNoneView];
        //把无消息View放到下一层  防止弹框遮盖
//        [self.view sendSubviewToBack:self.billSelectNoneView];
        
    }];
}

-(void)dealMessageResponse:(id)responseObject
{
    dispatch_async(dispatch_get_main_queue(), ^{
        
        BillSelectResponse *billResponse = [BillSelectResponse mj_objectWithKeyValues:responseObject];
        NSInteger tradeListCount = [billResponse.response.tradeList count];
        
        if (tradeListCount <= 0) {
            //无数据 加载无数据View
//            [self.tableView removeFromSuperview];
            [self.tableViewSectionArray removeAllObjects];
            self.billSelectNoneView = [[BillSelectNoneView alloc] initWithFrame:(CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50))];
            [self.view addSubview:self.billSelectNoneView];
            //把无消息View放到下一层  防止弹框遮盖
//            [self.view sendSubviewToBack:self.billSelectNoneView];

            
            
        }else
        {
            [self.view bringSubviewToFront:self.tableView];
            
            //条数
            NSInteger totalCount = 0;
            for (int i = 0; i < [billResponse.response.tradeList count]; i++) {
                totalCount = totalCount + [[billResponse.response.tradeList[i] list] count];
            }
            
            if (totalCount < 10) {
                self.ifHasMore = @"0";
            }else
            {
                self.ifHasMore = @"1";
            }
            
            
            if (self.refreshType == ETRefreshUp) {
                
                //如果月份是同一个月,不开启新的section
                Trade *oldtrade  = self.tableViewSectionArray.lastObject;
                for (Trade *trade in billResponse.response.tradeList) {
                    for (BillRecord *record in trade.list) {
                        NSLog(@"%@",record.payAmount);
                        //取到最里层数据
                        
                        if ([oldtrade.month isEqualToString:trade.month]) {
                            [oldtrade.list addObject:record];
                        }
                    }
              if (![oldtrade.month isEqualToString:trade.month]) {
                  [self.tableViewSectionArray addObject:trade];
              }else
              {
                  [self.tableViewSectionArray removeLastObject];
                  [self.tableViewSectionArray addObject:oldtrade];
              }
                    
                }
            }else if (self.refreshType == ETRefreshDown)
            {
                [self.tableViewSectionArray removeAllObjects];
                for (Trade *trade in billResponse.response.tradeList) {
                    for (BillRecord *record in trade.list) {
                        NSLog(@"%@",record.payAmount);
                        //取到最里层数据
                    }
                    [self.tableViewSectionArray addObject:trade];
                }
                
            }
            
            
            
        }
        
        [self.tableView reloadData];
    });
}


-(void)selectMonth
{
    [[[UIApplication sharedApplication].keyWindow viewWithTag:123456] removeFromSuperview];
    NSDate *minDate = [NSDate br_setYear:1900 month:1 day:1];
    NSDate *maxDate = [NSDate date];
    [BRDatePickerView showDatePickerWithTitle:nil addView:self.popfiltraView.datepickerView dateType:BRDatePickerModeYM defaultSelValue:self.popfiltraView.monthLab.text minDate:minDate maxDate:maxDate isAutoSelect:YES themeColor:nil resultBlock:^(NSString *selectValue) {
        
        NSLog(@"%@",selectValue);
        self.popfiltraView.monthLab.text = selectValue;
        
        //判断开始日期不能大于结束日期
        
    } cancelBlock:^{
        NSLog(@"点击了背景或取消按钮");
    }];
}
//点击开始时间
-(void)startTimeTapAction
{
    NSLog(@"点击开始时间");
    self.popfiltraView.dayLineView.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1];
    self.popfiltraView.dayEndLineView.layer.backgroundColor = [[UIColor colorWithRed:204.0f/255.0f green:204.0f/255.0f blue:204.0f/255.0f alpha:1.0f] CGColor];
    [[[UIApplication sharedApplication].keyWindow viewWithTag:123456] removeFromSuperview];
    NSDate *minDate = [NSDate br_setYear:1900 month:1 day:1];
    NSDate *maxDate = [NSDate date];
    [BRDatePickerView showDatePickerWithTitle:nil addView:self.popfiltraView.datepickerView dateType:BRDatePickerModeYMD defaultSelValue:self.popfiltraView.daybeginValueLab.text minDate:minDate maxDate:maxDate isAutoSelect:YES themeColor:nil resultBlock:^(NSString *selectValue) {
        
        NSLog(@"%@",selectValue);
        self.popfiltraView.daybeginValueLab.text = selectValue;
        
        //判断开始日期不能大于结束日期
        
    } cancelBlock:^{
        NSLog(@"点击了背景或取消按钮");
    }];
}
//点击结束时间
-(void)endTimeTapAction
{
    NSLog(@"点击结束时间");
    self.popfiltraView.dayEndLineView.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1];
    self.popfiltraView.dayLineView.layer.backgroundColor = [[UIColor colorWithRed:204.0f/255.0f green:204.0f/255.0f blue:204.0f/255.0f alpha:1.0f] CGColor];
    [[[UIApplication sharedApplication].keyWindow viewWithTag:123456] removeFromSuperview];
    NSDate *minDate = [NSDate br_setYear:1900 month:1 day:1];
    NSDate *maxDate = [NSDate date];
    [BRDatePickerView showDatePickerWithTitle:nil addView:self.popfiltraView.datepickerView dateType:BRDatePickerModeYMD defaultSelValue:self.popfiltraView.dayEndValueLab.text minDate:minDate maxDate:maxDate isAutoSelect:YES themeColor:nil resultBlock:^(NSString *selectValue) {
        
        NSLog(@"%@",selectValue);
        self.popfiltraView.dayEndValueLab.text = selectValue;
        
        //判断开始日期不能大于结束日期
        
    } cancelBlock:^{
        NSLog(@"点击了背景或取消按钮");
    }];
}
//按日查询
-(void)dayBtnAction
{
    
    [[[UIApplication sharedApplication].keyWindow viewWithTag:123456] removeFromSuperview];
    
    self.popfiltraView.selectDayView.hidden = NO;
    self.popfiltraView.selectMonthView.hidden = YES;
    
    //单选框效果
    if (self.popfiltraView.monthBtn.selected) {
        self.popfiltraView.monthBtn.selected = !self.popfiltraView.monthBtn.selected;
        self.popfiltraView.dayBtn.selected = !self.popfiltraView.dayBtn.selected;
    }
    
    //默认打开日期选择框
    [self startTimeTapAction];
    
    
}
//按月查询
-(void)monthBtnAction
{
    
    [[[UIApplication sharedApplication].keyWindow viewWithTag:123456] removeFromSuperview];
    
    self.popfiltraView.selectDayView.hidden = YES;
    self.popfiltraView.selectMonthView.hidden = NO;
    
    //单选框效果
    if (self.popfiltraView.dayBtn.selected) {
        self.popfiltraView.dayBtn.selected = !self.popfiltraView.dayBtn.selected;
        self.popfiltraView.monthBtn.selected = !self.popfiltraView.monthBtn.selected;
    }
    //点击按月查询自动打开日期选择框
    [self selectMonth];
    
}
#pragma mark  分类重置
-(void)resetBtnAction
{
    //默认选择第一行
    self.collectionViewSectionNum = 1;
    [self.pv.collectionView reloadData];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.pv.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
    
}
#pragma mark  分类确定
-(void)confirmBtnAction
{
    //清空月份、开始时间、结束时间、最低金额、最高金额
    self.month = nil;
    self.startTime = nil;
    self.endTime = nil;
    self.minAmount = nil;
    self.maxAmount = nil;
    //从第一页开始查
    self.curPageNum = 1;
    
    NSIndexPath *indexPath = self.pv.collectionView.indexPathsForSelectedItems[0];
    if (indexPath.section == 1) {
        SwipeCategoryCollectionViewCell *cell1 =  (SwipeCategoryCollectionViewCell *)[self.pv.collectionView cellForItemAtIndexPath:self.pv.collectionView.indexPathsForSelectedItems[0]];
        NSLog(@"%@",cell1.titleLab.text);
        //刷卡收款类
        [self.tableViewSectionArray removeAllObjects];
        [self.tableView reloadData];
        [self getBill];
        [self tapAction];
    }else
    {
        SwipeCategoryCollectionViewCell *cell =  (SwipeCategoryCollectionViewCell *)[self.pv.collectionView cellForItemAtIndexPath:self.pv.collectionView.indexPathsForSelectedItems[0]];
        NSLog(@"%@",cell.titleLab.text);
        //大类
        
        if (indexPath.row == 0) {
            self.orderType = nil;
        }else if (indexPath.row == 1)
        {
            self.orderType = @"0";
        }else if (indexPath.row == 2)
        {
            self.orderType = @"2";
        }
        
        [self.tableViewSectionArray removeAllObjects];
        [self getBill];
        [self.tableView reloadData];
        [self tapAction];
    }
    
    
    /*
    //返回之后更改筛选为蓝色筛选和图标
    [self.bv.categoryBtn setTintColor:[UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1]];
    [self.bv.categoryImvBtn setImage:[UIImage imageNamed:@"icon_arrow_downblue"] forState:(UIControlStateNormal)];
     */
    
    
}

-(void)createCollectionView
{
    self.collectionViewSectionNum = 1;
    //增加刷卡收款类型打开这条注释
    //    self.categoryArray = @[@"全部",@"信用卡收款",@"刷卡收款",@"提现"].mutableCopy;
//    self.swipeArray = @[@"全部",@"便利生活",@"家居礼品",@"餐饮行业",@"生活娱乐",@"珠宝首饰",@"汽车美容",@"票务加油"].mutableCopy;
    self.categoryArray = @[@"全部",@"信用卡收款",@"提现"].mutableCopy;
    self.pv.collectionView.backgroundColor = [UIColor orangeColor];
    self.pv.collectionView.delegate = self;
    self.pv.collectionView.dataSource = self;
    self.pv.collectionView.backgroundColor = [UIColor whiteColor];
    [self.pv.collectionView registerClass:[SwipeCategoryCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.pv.collectionView registerClass:[PopCategoryCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerCell"];
    
    //默认选择第一行
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.pv.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];

    
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.collectionViewSectionNum;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0) {
        return self.categoryArray.count;
    }else
    {
        return self.swipeArray.count;
    }
    
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SwipeCategoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        cell.titleLab.text = self.categoryArray[indexPath.row];
    }else
    {
        cell.titleLab.text = self.swipeArray[indexPath.row];
    }
    
    
    return cell;
}

#pragma mark - 头部视图大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    CGSize size = CGSizeMake(self.view.frame.size.width, 50);
    return size;
}
#pragma mark - 头部视图内容
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionReusableView *reusableView = nil;
    
    if (kind == UICollectionElementKindSectionHeader) {
        
        PopCategoryCollectionReusableView *headerView = (PopCategoryCollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerCell" forIndexPath:indexPath];
        
        
        if (indexPath.section == 0) {
            headerView.tipsLab.text = @"大类";
        }else if (indexPath.section == 1)
        {
            headerView.tipsLab.text = @"刷卡收款类";
        }
        
        reusableView = headerView;

        
    }
    return reusableView;
    
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    //增加刷卡收款类型打开这条注释
    /*
    [self.pv.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
     */
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //如果选中的是刷卡收款  增加一个分区并且刷卡收款被选中   增加刷卡收款类型打开这条注释
//    if (indexPath.section == 0 && indexPath.row == 2) {
     if (indexPath.section == 0 && indexPath.row == 3) {
        self.collectionViewSectionNum = 2;
        [self.pv.collectionView reloadData];
        self.pv.collectionView.allowsMultipleSelection = YES;
        [self.pv.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
        //打开一分区并且默认选中全部
        NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:0 inSection:1];
        [self.pv.collectionView selectItemAtIndexPath:indexPath1 animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
        //记录选择的全部，点击其他的取消选中
        self.lastIndexPath = indexPath1;
        
    }
    
    if (indexPath.section == 0 && indexPath.row != 2) {
        self.collectionViewSectionNum = 1;
        [self.pv.collectionView reloadData];
        self.pv.collectionView.allowsMultipleSelection = NO;
        [self.pv.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
    }
    
    //选中的一分区的
    if (indexPath.section == 1) {
        //0分区选了刷卡收款  点击1分区的刷卡收款还是选中
        self.pv.collectionView.allowsMultipleSelection = YES;
        NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:2 inSection:0];
        [self.pv.collectionView selectItemAtIndexPath:indexPath2 animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
        
        
            //记录上次选中的IndexPath  取消选中
        [self.pv.collectionView deselectItemAtIndexPath:self.lastIndexPath animated:NO];
            //取消第一个默认的
        if (self.pv.collectionView.indexPathsForSelectedItems.count == 3) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
            [self.pv.collectionView deselectItemAtIndexPath:indexPath animated:NO];
        }

        self.lastIndexPath = indexPath;
        [self.pv.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:(UICollectionViewScrollPositionNone)];
    }

}

//收回弹框
-(void)tapAction
{
    if (self.bv.categoryBtn.selected) {
        self.bv.categoryBtn.selected = !self.bv.categoryBtn.selected;
        self.bv.categoryImvBtn.selected = !self.bv.categoryImvBtn.selected;
        [self popCategory];
        
        //返回之后更改筛选为蓝色筛选和图标
        
        [self.bv.categoryBtn setTitleColor:ETColorWithRGB(91, 113, 255) forState:(UIControlStateNormal)];
        [self.bv.categoryImvBtn setImage:[UIImage imageNamed:@"icon_arrow_downblue"] forState:(UIControlStateNormal)];
        
        
        [self.bv.filtrateBtn setTitleColor:ETColorWithRGB(102, 102, 102) forState:(UIControlStateNormal)];
        [self.bv.filtrateImvBtn setImage:[UIImage imageNamed:@"icon_arrow_down"] forState:(UIControlStateNormal)];
        
        
        
    }else if (self.bv.filtrateBtn.selected)
    {
        self.bv.filtrateBtn.selected = !self.bv.filtrateBtn.selected;
        self.bv.filtrateImvBtn.selected = !self.bv.filtrateImvBtn.selected;
        [self popFiltrateView];
        
        //返回之后更改筛选为蓝色筛选和图标
        
        [self.bv.filtrateBtn setTitleColor:ETColorWithRGB(91, 113, 255) forState:(UIControlStateNormal)];
        [self.bv.filtrateImvBtn setImage:[UIImage imageNamed:@"icon_arrow_downblue"] forState:(UIControlStateNormal)];
        
        [self.bv.categoryBtn setTitleColor:ETColorWithRGB(102, 102, 102) forState:(UIControlStateNormal)];
        [self.bv.categoryImvBtn setImage:[UIImage imageNamed:@"icon_arrow_down"] forState:(UIControlStateNormal)];
    }
}
//点击筛选
-(void)filtrateClearBtnAction
{
    
    [self.bv.categoryBtn setTitleColor:ETColorWithRGB(102, 102, 102) forState:(UIControlStateNormal)];
    [self.bv.categoryImvBtn setImage:[UIImage imageNamed:@"icon_arrow_down"] forState:(UIControlStateNormal)];
    
    
    self.bv.filtrateBtn.selected = !self.bv.filtrateBtn.selected;
    self.bv.filtrateImvBtn.selected = !self.bv.filtrateImvBtn.selected;
    
    //把筛选View拿到最上层  防止弹框遮盖
    [self.view bringSubviewToFront:self.popfiltraView];
    [self.view bringSubviewToFront:self.bottomView];
    [self.view bringSubviewToFront:self.bv];
    

    
    //判断分类是否展示，如果展示的话先退出分类
    if (self.self.bv.categoryBtn.selected) {
        self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 0);
        
        [UIView animateWithDuration:0.5 animations:^{
            self.pv.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 110);
            
        } completion:^(BOOL finished) {
            self.bottomView.backgroundColor = [UIColor clearColor];
            
            //退出分类后打开筛选  退出分类后把分类按钮和图片置为初始值
            self.bv.categoryBtn.selected = !self.bv.categoryBtn.selected;
            self.bv.categoryImvBtn.selected = !self.bv.categoryImvBtn.selected;
            [self popFiltrateView];
        }];
    }else
    {
        //如果分类没打开  直接打开筛选
        [self popFiltrateView];
    }
}
//打开或关闭筛选方法
-(void)popFiltrateView
{
    if (self.bv.filtrateBtn.selected) {
        
        self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 60);
        
        [UIView animateWithDuration:0.5 animations:^{
            self.popfiltraView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 110);
        } completion:^(BOOL finished) {
            
            //展示picker
            
            if (self.popfiltraView.monthBtn.selected) {
                [self selectMonth];
            }else if(self.popfiltraView.dayBtn.selected)
            {
                [self endTimeTapAction];
                [self startTimeTapAction];
            }
            
            

            self.bottomView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        }];
        
        
    }else
    {
        self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 0);
        
        [UIView animateWithDuration:0.5 animations:^{
            self.popfiltraView.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 110);
            
        } completion:^(BOOL finished) {
            self.bottomView.backgroundColor = [UIColor clearColor];
        }];
    }
}

//点击分类
-(void)categoryBtnAction
{
    
    [self.bv.filtrateBtn setTitleColor:ETColorWithRGB(102, 102, 102) forState:(UIControlStateNormal)];
    [self.bv.filtrateImvBtn setImage:[UIImage imageNamed:@"icon_arrow_down"] forState:(UIControlStateNormal)];
    
    //把分类View拿到最上层  防止弹框遮盖
    [self.view bringSubviewToFront:self.pv];
    [self.view bringSubviewToFront:self.bottomView];
    [self.view bringSubviewToFront:self.bv];
    
    self.bv.categoryBtn.selected = !self.bv.categoryBtn.selected;
    self.bv.categoryImvBtn.selected = !self.bv.categoryImvBtn.selected;
    
    //判断筛选是否展示，如果展示的话先退出筛选
    if (self.bv.filtrateBtn.selected) {
        self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 0);
        
        [UIView animateWithDuration:0.5 animations:^{
            self.popfiltraView.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 110);
            
        } completion:^(BOOL finished) {
            self.bottomView.backgroundColor = [UIColor clearColor];
            //退出筛选后打开分类  退出筛选后把筛选按钮和图片置为初始值
            [self popCategory];
            self.bv.filtrateBtn.selected = !self.bv.filtrateBtn.selected;
            self.bv.filtrateImvBtn.selected = !self.bv.filtrateImvBtn.selected;
            
        }];
    }else
    {
        //如果筛选没打开  直接打开分类
        [self popCategory];
    }
    
}
//打开或关闭分类方法
-(void)popCategory
{
    if (self.bv.categoryBtn.selected) {
        
        self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 60);
        
        [UIView animateWithDuration:0.5 animations:^{
            self.pv.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 110);
        } completion:^(BOOL finished) {
            self.bottomView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        }];
        
        
    }else
    {
        self.bottomView.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 0);
        
        [UIView animateWithDuration:0.5 animations:^{
            self.pv.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 110);
            
        } completion:^(BOOL finished) {
            self.bottomView.backgroundColor = [UIColor clearColor];
        }];
    }
}
-(void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, ETScreenW, ETScreenH - 50 - ETTopHeight - ETTabBarArcHeight) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = ETColorWithRGB(242, 244, 246);
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[BillSelectTableViewCell class] forCellReuseIdentifier:@"cell"];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.tableViewSectionArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.tableViewSectionArray.count > 0) {
        for (int i = 0; i < self.tableViewSectionArray.count; i++) {
            if (section == i) {
                return [[self.tableViewSectionArray[i] list] count];
            }
        }
    }
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BillSelectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//        cell.imv.image = [UIImage imageNamed:self.imageArray[indexPath.row]];
        for (int i = 0 ; i < self.tableViewSectionArray.count; i++) {
            for (int j =  0; j < [[self.tableViewSectionArray[i] list] count]; j++) {
                
                //修改每个分区的最后一个cell不显示线条
                if (indexPath.section == i) {
                    if (indexPath.row == [self.tableViewSectionArray[i] list].count - 1) {
                        cell.lineView.hidden = YES;
                    }else
                    {
                        cell.lineView.hidden = NO;
                    }
                    
                }
                
                
                if (indexPath.section == i && indexPath.row == j) {
                    BillRecord *record = [self.tableViewSectionArray[i] list][j];
                    
                    if ([@"0" isEqualToString:record.orderType]) {
                        cell.titleLab.text = @"信用卡收款";
                        cell.imv.image = [UIImage imageNamed:@"bill_icon_card"];
                    }else if ([@"1" isEqualToString:record.orderType]) {
                        cell.titleLab.text = @"刷卡收款";
                        cell.imv.image = [UIImage imageNamed:@"bill_icon_shua"];
                    }else if ([@"2" isEqualToString:record.orderType]) {
                        cell.titleLab.text = @"提现";
                        cell.imv.image = [UIImage imageNamed:@"bill_icon_cash"];
                    }else
                    {
                        cell.titleLab.text = @"未知类型";
                        cell.imv.image = [UIImage imageNamed:@"bill_icon_card"];
                        
                    }
                    
                    
                    cell.detailLab.text = record.tardeType;
                    cell.timeLab.text = record.tradeTime;
                    cell.moneyNumLab.text = record.payAmount;
                    cell.consumeStateLab.text = record.statusName;
                    
                    //修改交易状态显示颜色
                    if ([record.statusName isEqualToString:@"交易中"]) {
                        cell.consumeStateLab.textColor = ETColorWithRGB(91, 113, 255);
                    }else if ([record.statusName isEqualToString:@"交易成功"])
                    {
                        cell.consumeStateLab.textColor = ETColorWithRGB(153, 153, 153);
                    }else if ([record.statusName isEqualToString:@"交易失败"])
                    {
                        cell.consumeStateLab.textColor = ETColorWithRGB(252, 92, 76);
                    }
                    
                }
            }
        }

    
    
    
    //点击不变色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BillRecord *record = [self.tableViewSectionArray[indexPath.section] list][indexPath.row];
    //获取收款卡号
    BillSelectDetailRequest *request = [[BillSelectDetailRequest alloc] init];
    request.detailId = record.detailId;
    NSDictionary *dic = [request mj_keyValues];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/order/getOrderDetail"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealDetailResponse:responseObject record:record];
        }
        
    } FailedHandler:^(NSError *error) {
        
    }];
    
    
}
-(void)dealDetailResponse:(id)responseObject record:(BillRecord *)billrecord
{
    
    BillSelectDetailResponse *billResponse = [BillSelectDetailResponse mj_objectWithKeyValues:responseObject];
    BillDetailRecord *record = billResponse.response.orderDetail;
    NSLog(@"%@",billResponse.response.orderDetail.receiveCardNo);
    
    if (billResponse.response.orderDetail.receiveCardNo.length != 0) {
        BillDetailViewController *billVC = [[BillDetailViewController alloc] init];
        billVC.payAmount = record.transAmt;
        if ([record.status isEqualToString:@"1"]) {
            billVC.statusName = @"交易中";
        }else if ([record.status isEqualToString:@"2"])
        {
            billVC.statusName = @"交易成功";
        }else if ([record.status isEqualToString:@"3"])
        {
            billVC.statusName = @"交易失败";
        }
        billVC.businessType = record.orderType;
        billVC.receiveCardNo = record.receiveCardNo;
        billVC.orderId = record.ID;
        billVC.tradeTime = record.transTime;
        [self.navigationController pushViewController:billVC animated:YES];
    }
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50.00f;
}

-(void)createTopView
{
    self.bv = [[BillSelectView alloc] init];
    self.bv.backgroundColor = [UIColor whiteColor];
    self.bv.frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
    [self.view addSubview:self.bv];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    self.sectionHeaderView = [[BillSelectSectionHeaderView alloc] init];
    for (int i = 0;i < self.tableViewSectionArray.count;i++) {
        if (section == i) {
            Trade *trade = self.tableViewSectionArray[i];
            [self.sectionHeaderView.dateBtn setTitle:[trade month] forState:(UIControlStateNormal)];
            /*
            self.sectionHeaderView.consumeTimesLab.text = [NSString stringWithFormat:@"%@%@%@",@"交易笔数 ",[trade totalCount],@"笔"];
            self.sectionHeaderView.consumeLab.text = [NSString stringWithFormat:@"%@%@",@"交易成功 ￥",[trade totalAmount]];
             */
        }
       
    }
    
    return self.sectionHeaderView;

}
//退键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [self.popfiltraView.minimumAmountTf resignFirstResponder];
    [self.popfiltraView.maxAmountTf resignFirstResponder];
}
//退键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.popfiltraView.minimumAmountTf resignFirstResponder];
    [self.popfiltraView.maxAmountTf resignFirstResponder];
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return [self validateNumber:string];
}

- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}
#pragma mark  筛选重置按钮
-(void)popfiltraresetAction
{
    NSLog(@"点击筛选--》重置按钮");
    self.popfiltraView.minimumAmountTf.text = @"";
    self.popfiltraView.maxAmountTf.text = @"";
    self.popfiltraView.monthLab.text = [self getCurrentMonthDate];
    self.popfiltraView.daybeginValueLab.text = [self getCurrentDayDate];
    self.popfiltraView.dayEndValueLab.text = [self getCurrentDayDate];
    if (self.popfiltraView.monthBtn.selected) {
        [self monthBtnAction];
    }
    
    if (self.popfiltraView.dayBtn.selected) {
        [self endTimeTapAction];
        [self startTimeTapAction];
    }
    
}
#pragma mark 筛选确定按钮
-(void)popfiltraconfirmAction
{
    NSLog(@"点击筛选--》确定按钮");
    //从第一页开始查
    self.curPageNum = 1;
    //清空类型
    self.orderType = nil;
    if (self.popfiltraView.minimumAmountTf.text.length != 0 || self.popfiltraView.maxAmountTf.text.length != 0) {
        if (self.popfiltraView.minimumAmountTf.text.length == 0) {
            [self showFailedResultTips:@"请输入最低金额" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
            return;
        }
        
        if (self.popfiltraView.maxAmountTf.text.length == 0) {
            [self showFailedResultTips:@"请输入最高金额" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
            return;
        }
        
        if ([self.popfiltraView.minimumAmountTf.text floatValue] > [self.popfiltraView.maxAmountTf.text floatValue]) {
            [self showFailedResultTips:@"最小金额不能大于最大金额" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
            return;
        }
    }
    
    if (self.popfiltraView.monthBtn.selected) {
        NSLog(@"按月选择");
        //分类为空、最大时间、最小时间为空
        if (self.popfiltraView.minimumAmountTf.text.length == 0) {
            self.minAmount = nil;
        }else
        {
            self.minAmount = self.popfiltraView.minimumAmountTf.text;
        }
        
        if (self.popfiltraView.maxAmountTf.text.length == 0) {
            self.maxAmount = nil;
        }else
        {
            self.maxAmount = self.popfiltraView.maxAmountTf.text;
        }
        
        if (self.popfiltraView.monthLab.text.length == 0) {
            self.month = nil;
        }else
        {
            self.month = self.popfiltraView.monthLab.text;
        }
        
        self.startTime = nil;
        self.endTime = nil;
        [self.tableViewSectionArray removeAllObjects];
        [self.tableView reloadData];
        [self getBill];
        [self tapAction];
    }
    
    if (self.popfiltraView.dayBtn.selected) {
        NSLog(@"按日选择");
        //分类为空、月份为空
      NSInteger i = [self compareOneDay:self.popfiltraView.daybeginValueLab.text withAnotherDay:self.popfiltraView.dayEndValueLab.text];
        if (i == 1) {
            [self showFailedResultTips:@"开始时间不能比结束时间晚" animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
            return;
        }
        
        NSString *dayBeginStr = [NSString stringWithFormat:@"%@%@%@",self.popfiltraView.daybeginValueLab.text,@" ",@"00:00:00"];
        NSString *dayEndStr = [NSString stringWithFormat:@"%@%@%@",self.popfiltraView.dayEndValueLab.text,@" ",@"24:00:00"];
        
        if (self.popfiltraView.minimumAmountTf.text.length == 0) {
            self.minAmount = nil;
        }else
        {
            self.minAmount = self.popfiltraView.minimumAmountTf.text;
        }
        
        if (self.popfiltraView.maxAmountTf.text.length == 0) {
            self.maxAmount = nil;
        }else
        {
            self.maxAmount = self.popfiltraView.maxAmountTf.text;
        }
        
        self.startTime = dayBeginStr;
        self.endTime = dayEndStr;
        self.month = nil;
        [self.tableViewSectionArray removeAllObjects];
        [self.tableView reloadData];
        [self getBill];
        [self tapAction];
    }
    
    
    /*
    //返回之后更改筛选为蓝色筛选和图标
    [self.bv.filtrateBtn setTintColor:[UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1]];
    [self.bv.filtrateImvBtn setImage:[UIImage imageNamed:@"icon_arrow_downblue"] forState:(UIControlStateNormal)];
     */
    
}

- (NSInteger )compareOneDay:(NSString *)beginStr withAnotherDay:(NSString *)endStr
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *dateA = [dateFormatter dateFromString:beginStr];
    
    NSDate *dateB = [dateFormatter dateFromString:endStr];
    
    NSComparisonResult result = [dateA compare:dateB];
    
    if (result == NSOrderedDescending) {
        //NSLog(@"beginStr比 endStr时间晚");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"beginStr比 endStr时间早");
        return -1;
    }
    //NSLog(@"两者时间是同一个时间");
    return 0;
    
}

@end
